package com.cngphone.AnFetion;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FetionUri {
    private static final Pattern p1 = Pattern.compile("sip:(.*?)@(.*?);p=(.*)$");
    private static final Pattern p2 = Pattern.compile("tel:(.*)$");
    protected String id;
    protected String domain;
    protected String p;

    public FetionUri(String uri) {
        Matcher m = p1.matcher(uri);
        if (m.find()) {
            this.id = m.group(1);
            this.domain = m.group(2);
            this.p = m.group(3);
        } else {
            m = p2.matcher(uri);
            if (m.find()) {
                this.id = m.group(1);
            }
        }
    }

    @Override
    public String toString() {
        if (p != null) {
            return "sip:" + this.id + "@" + this.domain + ";p=" + this.p;
        } else {
            return "tel:" + this.id;
        }
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    public String getP() {
        return p;
    }

    public void setP(String p) {
        this.p = p;
    }

}
